<template>
  <view>
    <!-- 没有绑定邀请码 -->
    <view class="shuru" v-if="code === 0">
      <!-- 填写邀请码 -->
      <view class="codetitle">请填写您的邀请码</view>
      <form>
        <view class="ipt">
          <input
            class="ipt-2"
            v-model="invitecode"
            type="text"
            placeholder="请输入邀请码"
          />
        </view>
      </form>
      <view class="p-b-30" @click="handleSubmit">
        <view class="btn br-60 w-580 h-80 t_c lh-80">提交</view>
      </view>
    </view>
    <!-- 绑定了邀请码 -->
    <view class="bound" v-else>
      <!-- 绑定图片 -->
      <img
        class="mt-200"
        src="https://tzdj.1qit.com/assets/wx_imgs/my/boundimg.png"
        alt=""
      />
      <view class="mt-60">{{ msg }}</view>
      <view class="mt-100 homebtn br-60 w-580 h-80 t_c lh-80" @click="toHome"
        >返回首页</view
      >
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      // 邀请码
      invitecode: "",
      // 状态
      code: 0,
      // 提示信息
      msg: "状态信息",
    };
  },
  onLoad() {},
  mounted() {
    // 判断是否绑定了邀请码
    uni.request({
      url: "http://jjdj.hongliwangluo.com/api/common/check_bind_invitation",
      header: {
        token: uni.getStorageSync("token"),
      },
      success: (res) => {
        console.log(res.data.msg);
        this.code = res.data.code;
        this.msg = res.data.msg;
      },
    });
  },
  methods: {
    // 提交邀请码
    async handleSubmit() {
      let data = await this.$request.post("/api/common/bind_invitation", {
        invitation_code: this.invitecode,
      });
      console.log(data);
      if (data.data.code === 1) {
        uni.showToast({
          title: "邀请码绑定成功",
          duration: 1500,
        });
        setTimeout(() => {
          // uni.navigateTo({
          //   url: "pages/driver/driverMy/index",
          // });
          uni.redirectTo({
            url: "pages/driver/driverMy/index",
          });
        }, 1500);
      }
    },
    toHome() {
      // 去首页
      uni.navigateTo({
        url: "/pages/driver/receiveOrder/index",
      });
    },
  },
};
</script>

<style scoped>
.btn {
  background: #0a5aff;
  color: #fff;
}
.ipt {
  line-height: 80rpx;
  border-radius: 60rpx;
  width: 580rpx;
  height: 80rpx;
  border: 1px solid #ccc;
}
.ipt-2 {
  text-align: center;
  height: 80rpx;
  line-height: 80rpx;
}
.bound {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
.homebtn {
  border: 1px solid #0a5aff;
  color: #0a5aff;
}
.mt-200 {
  margin-top: 200rpx;
}
.mt-60 {
  margin-top: 60rpx;
}
.mt-100 {
  margin-top: 100rpx;
}
.shuru {
  background: #fff;
  margin: 0 auto;
  width: 90%;
  height: 800rpx;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  margin-top: 40rpx;
  box-shadow: -1rpx 1rpx 4rpx 0rpx #ccc;
}
.codetitle {
  font-size: 40rpx;
}
</style>